/*
 * @Author: CodeHare
 * @Date: 2023-11-30 16:45:54
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2023-12-15 14:49:13
 * @Description: 站点模块Tab
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:yt_devops/components/app_permission/yt_tab_view_model.dart';
import 'package:yt_devops/pages/site/site_device_manager/site_device_manager_view.dart';
import 'package:yt_devops/pages/site/site_overview/site_overview_view.dart';
import 'package:yt_devops/pages/site/site_setting/site_setting_view.dart';
import 'package:yt_devops/pages/site/site_statis_data/site_statis_data_view.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';

/// 站点Tab
class SiteTabController extends GetxController
    with GetTickerProviderStateMixin {
  int selectedIndex = 0;
  int siteId = 0;
  String energyOptions = '';
  String monetaryUnitName = '';
  TabController? tabController;
  GetStorage storage = GetStorage();
  List<Widget> sitePages = [];
  List<BottomNavigationBarItem> items = [];
  List<YtTabViewModel> permissionGroups = [];
  @override
  void onInit() {
    super.onInit();

    if (Get.arguments != null) {
      siteId = Get.arguments['id'];
      if (Get.arguments['energyOptions'] != null) {
        energyOptions = Get.arguments['energyOptions'];
      }
      if (Get.arguments['monetaryUnitName'] != null) {
        monetaryUnitName = Get.arguments['monetaryUnitName'];
        if (monetaryUnitName == '元' || monetaryUnitName == '¥') {
          monetaryUnitName = ResKey.yuan.tr;
        }
        storage.write('monetaryUnitName', monetaryUnitName);
      }
      YtTabViewModel model1 = YtTabViewModel(permissionString: PermissionConstant.homeSiteManageOverview,
          labelString: ResKey.siteOverview.tr,imageString: ImageAssets.siteOverviewDef,
          permissionWidget: SiteOverviewView());
      YtTabViewModel model2 = YtTabViewModel(permissionString: PermissionConstant.homeSiteManageDataStatistics,
          labelString: ResKey.dataStatistics.tr,imageString: ImageAssets.siteStatisDataDef,
          permissionWidget: const SiteStatisDataView());
      YtTabViewModel model3 = YtTabViewModel(permissionString: PermissionConstant.homeSiteManageDeviceMonitor,
          labelString: ResKey.deviceMonitor.tr,imageString: ImageAssets.siteDeviceManagerDef,
          permissionWidget: SiteDeviceManagerView());
      YtTabViewModel model4 = YtTabViewModel(permissionString: PermissionConstant.homeSiteManageSetting,
          labelString: ResKey.siteOverviewSiteSet.tr,imageString: ImageAssets.siteDetailDef,
          permissionWidget: SiteSettingView());
      permissionGroups.add(model1);
      permissionGroups.add(model2);
      permissionGroups.add(model3);
      permissionGroups.add(model4);
    }
  }


  @override
  void onReady() {}


  onItemTapped(index) {
    selectedIndex = index;
    // tabController?.animateTo(index);
    update();
  }
}
